
package dashboard;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class NotificationController {




	public NotificationController()

	{

	}

	public static List<Notification> checkNotifications(User user)
	{
		List<Notification> notifications = new ArrayList<Notification>();
		User cUser = user;
		List<Milestone> milestones = cUser.getMilestones();
		Date now = new Date();
		List<Long> courses = cUser.getCourses();

		for(Milestone milestone: milestones )
		{
				if(Statistics.getProgressMilestone(milestone, cUser)>=100 && milestone.getEnd().after(cUser.getPreviousLastLogin()))
				{
					if(milestone.isViewed()==false){
				Notification not = new Notification(3,milestone.getId());
				notifications.add(not);
				milestone.setViewed();
				UserRegistry.getInstance().addUser(cUser);
					}
				}
				
				else if((milestone.getEnd().getTime() - now.getTime())/86400 < 7000 && !Statistics.milestoneIsAchieved(milestone, cUser))
				{
					Notification not = new Notification(1, milestone.getId());
					notifications.add(not);
				}
				else if(milestone.getEnd().before(now) && !Statistics.milestoneIsAchieved(milestone, cUser) && milestone.getEnd().after(cUser.getPreviousLastLogin()))
				{
					Notification not = new Notification(4,milestone.getId());
					notifications.add(not);
					milestone.setViewed();
					UserRegistry.getInstance().addUser(cUser);
				}
			}


			for(Long course: courses)
			{
				if(Statistics.getPositionOfCourseStudyTime(cUser, course) < cUser.getTreshold())
				{
					Notification not = new Notification(2, course);
					notifications.add(not);
				}
			}

			return notifications;

		
	}
	}